package p2;
/**
 * This class implements the doorman's part of the
 * Barbershop thread synchronization example.
 */
public class Doorman extends Thread {
	
	private CustomerQueue queue;
	private Gui gui;
	private boolean running;
	
	/**
	 * Creates a new doorman.
	 * @param queue		The customer queue.
	 * @param gui		A reference to the GUI interface.
	 */
	public Doorman(CustomerQueue queue, Gui gui) { 
		this.queue = queue;
		this.gui = gui;
	}

	/**
	 * Starts the doorman running as a separate thread.
	 */
	public void startThread() {
		running = true;
		System.out.println("Start running doorman");
		start();
	}

	/**
	 * Stops the doorman thread.
	 */
	public void stopThread() {
		running = false;
	}

	@Override
	public void run() { // flyttet litt gui logikk ut fra denne og inn i CustomerQueue
		while(running) {
			Customer customer = new Customer();
			queue.addCustomer(customer); // Monitor Lock
			// Monitor release
			
			try { Thread.sleep(Globals.doormanSleep);	} 
			catch (InterruptedException e) { }
			
		}
		
	}

	// Add more methods as needed
}
